package Hot100;

import java.util.ArrayList;
import java.util.List;

public class 划分字母区间 {
    public List<Integer> partitionLabels(String s) {
        List<Integer> res = new ArrayList<>();
        int[] ends = new int[26];
        char[] chars = s.toCharArray();
        int len = chars.length;
        for (int i = 0; i < len; i++) {
            ends[chars[i] - 'a'] = i;
        }
        int split = 0;
        int last = -1;
        for (int i = 0; i < len; i++) {
            split = Math.max(split, ends[chars[i] - 'a']);
            if (i == split) {
                res.add(split - last);
                last = i;
            }
        }
        return res;
    }
}
